/**
 * 日志管理初始化
 */
var LoginLog = {
    table: null
};

LoginLog.init = function () {
    layui.form.render();
    var me = this;
    this.table = new LayUITable("table", "/system/sysLoginLog/list", this.initColumns());
    me.table.params = {
        height: $(".dawn-content").height() - 50
    }
    me.table.setQueryParams(me.queryParams);
    me.table.handleListenToolBar = function (event, checkStatus, obj) {
        switch (event) {
            case "clear":
                Dawn.deleteConfirm("是否清空所有日志?", function () {
                    $request.get("/system/sysLoginLog/delLoginLog", function (data) {
                        if(data.success) {
                            Dawn.success("操作成功!");
                            LoginLog.table.refresh();
                        } else {
                            Dawn.error(data.message);
                        }
                    }).start();
                });
                break;
        }
    };
    me.table.init();
    this.addEvents();
};

/**
 * 初始化表格的列
 */
LoginLog.initColumns = function () {
    return [[
        {title: 'id', field: 'id', hide: true, align: 'center'},
        {title: '日志名称', field: 'logname', align: 'center', sort: true},
        {title: '用户名称', field: 'userName', align: 'center'},
        {title: '时间', field: 'createtime', align: 'center', sort: true},
        {title: '具体消息', field: 'message', align: 'center', sort: true},
        {title: 'ip', field: 'ip', align: 'center', sort: true}]];
};

LoginLog.addEvents = function () {
    var me = this;
    $("#search").click(function () {
        me.search();
    })
    $("#reset").click(function () {
        me.reset();
    });
}

LoginLog.reset = function () {
    $("#logName").val("");
    $("#time").val("");
    layui.form.render();
    this.search();
}

LoginLog.search = function () {
    this.table.init();
}

LoginLog.queryParams = function () {
    var queryData = {};
    queryData['logName'] = $("#logName").val();
    var time = $("#time").val();
    if (time != "") {
        var args = time.split(" - ");
        queryData['beginTime'] = $.trim(args[0]);
        queryData['endTime'] = $.trim(args[1]);
    }
    return queryData;
}


$(function () {
    layui.element.init();
    LoginLog.init();
});

